﻿using System;
using ltModel;

public partial class ltMan_infos_infoAdd : AdminBasePage
{
    ltModel.BLL.TableDownload tbl = new ltModel.BLL.TableDownload();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.QueryString["id"];
            if (Str.IsInt(id))
            {
                ltModel.Model.TableDownload tbo = tbl.GetModel(int.Parse(id));
                txt_tname.Text = tbo.tname;
                txt_bm_name.Text = tbo.bm_name;
                txt_yu_name.Text = tbo.yu_name;
                txt_info.Text = tbo.info;
                txt_url.Text = tbo.link;
            }
        }
    }
    protected void RadSave_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        bool inEdit = Str.IsInt(id);
        ltModel.Model.TableDownload tbo = null;
        if (inEdit)
            tbo = tbl.GetModel(int.Parse(id));
        else
            tbo = new ltModel.Model.TableDownload();

        tbo.tname = DataProtector.ToSBC(txt_tname.Text.Trim());
        tbo.bm_name = DataProtector.ToSBC(txt_bm_name.Text.Trim());
        tbo.yu_name = DataProtector.ToSBC(txt_yu_name.Text.Trim());
        tbo.info = DataProtector.ToSBC(txt_info.Text.Trim());

        string file = tFile.SaveFiles();
        if (!string.IsNullOrEmpty(file))
            tbo.link = file;
        else
        {
            if (!string.IsNullOrEmpty(txt_url.Text))
                tbo.link = DataProtector.ToSBC(txt_url.Text.Trim());
        }

        if (inEdit)
        {
            tbl.Update(tbo);
            OperateLog.AddSuccessLog(CurrentUser.user_id, Request.UserHostAddress, "资料下载-修改>" + tbo.tname);
        }
        else
        {
            tbo.addtime = DateTime.Now.ToString();
            tbo.zt = 1;
            tbo.downs = 0;
            tbo.fbren = CurrentUser.username;
            tbl.Add(tbo);
            OperateLog.AddSuccessLog(CurrentUser.user_id, Request.UserHostAddress, "资料下载-添加>" + tbo.tname);
        }

        infoPanel.AddSuccessInfo(inEdit ? "修改成功" : "添加成功");
        AddScriptM("setTimeout(parent.reloadData, 300);");
    }
}